﻿using Albatross.WPF.Common;
using Albatross.WPF.Common.ViewModels;
using Albatross.WPF.Common.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Albatross.SampleClient.ViewModels {
	[DataContract]
	public class CompositeMainViewModel : WorkspaceViewModel {
		public CompositeMainViewModel() {
			Title = "Composite Main";
		}

		public RelayCommand<IViewService> Test1Command { get { return new RelayCommand<IViewService>(Test1, CanTest1); } }
		void Test1(IViewService svcs) {
			string region = "Region1";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest1(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test2Command { get { return new RelayCommand<IViewService>(Test2, CanTest2); } }
		void Test2(IViewService svcs) {
			string region = "Region2";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest2(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test3Command { get { return new RelayCommand<IViewService>(Test3, CanTest3); } }
		void Test3(IViewService svcs) {
			string region = "Region3";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest3(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test4Command { get { return new RelayCommand<IViewService>(Test4, CanTest4); } }
		void Test4(IViewService svcs) {
			string region = "Region4";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct); 
		}
		bool CanTest4(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test5Command { get { return new RelayCommand<IViewService>(Test5, CanTest5); } }
		void Test5(IViewService svcs) {
			string region = "Region5";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest5(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test6Command { get { return new RelayCommand<IViewService>(Test6, CanTest6); } }
		void Test6(IViewService svcs) {
			string region = "Region6";
			IWorkspaceConstruct construct = new WorkspaceConstruct<TestViewModel>(region){ Region = region, };
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest6(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test1CompositeCommand { get { return new RelayCommand<IViewService>(Test1Composite, CanTest1Composite); } }
		void Test1Composite(IViewService svcs) {
			string region = "Region1";
			IWorkspaceConstruct construct = new WorkspaceConstruct<Composite1ViewModel>(region);
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest1Composite(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test2CompositeCommand { get { return new RelayCommand<IViewService>(Test2Composite, CanTest2Composite); } }
		void Test2Composite(IViewService svcs) {
			string region = "Region2";
			IWorkspaceConstruct construct = new WorkspaceConstruct<Composite2ViewModel>(region);
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest2Composite(IViewService svcs) { return true; }

		public RelayCommand<IViewService> Test3CompositeCommand { get { return new RelayCommand<IViewService>(Test3Composite, CanTest3Composite); } }
		void Test3Composite(IViewService svcs) {
			string region = "Region3";
			IWorkspaceConstruct construct = new WorkspaceConstruct<Composite2ViewModel>(region);
			construct.Region = region;
			svcs.ShowWorkspace(construct);
		}
		bool CanTest3Composite(IViewService svcs) { return true; }

		public const string PromptPropertyName = "CanClose";
		private bool _canClose;
		public bool CanClose {
			get { return _canClose; }
			set {
				if (_canClose == value) { return; }
				RaisePropertyChanging(PromptPropertyName);
				_canClose = value;
				RaisePropertyChanged(PromptPropertyName);
			}
		}
		public override bool Closing(WPF.Common.IViewService svcs) {
			if (!CanClose) {
				if (svcs != null) {
					return svcs.ShowConfirmationMessageBox("Are you sure that you want to close " + Title);
				} else {
					return false;
				}
			} else {
				return true;
			}
		}
	}
}
